//
//  HNSH_ConfirmOrderAddressCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/26.
//

#import "HNSH_ConfirmOrderAddressCell.h"

@interface HNSH_ConfirmOrderAddressCell ()

/* iconImgV */
@property (nonatomic, strong) UIImageView *iconImgV;
/* nameLabel */
@property (nonatomic, strong) UILabel *nameLabel;
/* addressLabel */
@property (nonatomic, strong) UILabel *addressLabel;


/* showImgV */
@property (nonatomic, strong) UIImageView *showImgV;
/* bottomImgV */
@property (nonatomic, strong) UIImageView *bottomImgV;

/* nullLabel */
@property (nonatomic, strong) UILabel *nullLabel;

@end

@implementation HNSH_ConfirmOrderAddressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor appWhiteLabelColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self configUI];
    }
    return self;
}

- (void)setModel:(HNSH_AddressModel *)model {
    _model = model;
    self.nameLabel.text = model.contact ? model.contact : [NSString stringWithFormat:@"%@ %@", model.name, model.phone];
    self.addressLabel.text =  model.address ? model.address : [NSString stringWithFormat:@"%@%@%@%@", model.province_name, model.city_name, model.county_name, model.details];
    
    self.nullLabel.hidden = [model.uid integerValue] > 0;
    self.nameLabel.hidden = self.addressLabel.hidden = !self.nullLabel.hidden;
}

- (void)configUI {
    [self.contentView addSubview:self.iconImgV];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.showImgV];
    [self.contentView addSubview:self.bottomImgV];
    [self.contentView addSubview:self.nullLabel];
    
    [self.iconImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(34);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgV.mas_right).offset(8);
        make.top.mas_equalTo(20);
        make.height.mas_equalTo(22);
    }];
    
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconImgV.mas_right).offset(8);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(6);
        make.height.mas_equalTo(20);
        make.width.mas_equalTo(kScreenWidth-100);
    }];
    
    [self.showImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImgV.mas_centerY);
        make.right.mas_equalTo(-20);
        make.width.mas_equalTo(7);
        make.height.mas_equalTo(13);
    }];
    
    [self.bottomImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(2);
    }];
    
    [self.nullLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImgV.mas_centerY);
        make.left.equalTo(self.iconImgV.mas_right).offset(8);
        make.height.mas_equalTo(22);
    }];
}

#pragma mark lazy
- (UIImageView *)iconImgV {
    if (!_iconImgV) {
        _iconImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shop_confirm_address_icon"]];
    }
    return _iconImgV;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.text = @"";
        _nameLabel.textColor = [UIColor appBlackLabelColor];
        _nameLabel.font = [UIFont systemFontOfSize:16];
    }
    return _nameLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc]init];
        _addressLabel.text = @"";
        _addressLabel.textColor = [UIColor appGrayLabelColor];
        _addressLabel.font = [UIFont systemFontOfSize:14];
    }
    return _addressLabel;
}

- (UILabel *)nullLabel {
    if (!_nullLabel) {
        _nullLabel = [[UILabel alloc]init];
        _nullLabel.text = @"请选择收货地址";
        _nullLabel.textColor = [UIColor appBlackLabelColor];
        _nullLabel.font = [UIFont systemFontOfSize:16];
    }
    return _nullLabel;
}

- (UIImageView *)showImgV {
    if (!_showImgV) {
        _showImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"goods_detail_show"]];
    }
    return _showImgV;
}

- (UIImageView *)bottomImgV {
    if (!_bottomImgV) {
        _bottomImgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shop_confirm_address_bottom"]];
    }
    return _bottomImgV;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
